﻿namespace Home
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web;

    public static class WebsiteStateHelper
    {
        public static class Application
        {
            public static T Get<T>(string key)
            {
                Debug.Assert(!string.IsNullOrEmpty(key));

                throw new NotImplementedException();
            }

            public static void Set<T>(string key, T value)
            {
                Debug.Assert(!string.IsNullOrEmpty(key));

                throw new NotImplementedException();
            }

            public static void Remove(string key)
            {
                Debug.Assert(!string.IsNullOrEmpty(key));

                throw new NotImplementedException();
            }
        }

        public static class Session
        {
            public static T Get<T>(string key)
            {
                Debug.Assert(!string.IsNullOrEmpty(key));

                throw new NotImplementedException();
            }

            public static void Set<T>(string key, T value)
            {
                Debug.Assert(!string.IsNullOrEmpty(key));

                throw new NotImplementedException();
            }

            public static void Remove(string key)
            {
                Debug.Assert(!string.IsNullOrEmpty(key));

                throw new NotImplementedException();
            }
        }

        public static class Request
        {
            public static T Get<T>(string key)
            {
                Debug.Assert(!string.IsNullOrEmpty(key));

                if (HttpContext.Current.Items.Contains(key))
                {
                    var item = HttpContext.Current.Items[key];
                    return (T)item;
                }

                return default(T);
            }

            public static void Set<T>(string key, T value)
            {
                Debug.Assert(!string.IsNullOrEmpty(key));

                if (object.Equals(default(T), value) && HttpContext.Current.Items.Contains(key))
                {
                    HttpContext.Current.Items.Remove(key);
                }
                else
                {
                    HttpContext.Current.Items[key] = value;
                }
            }

            public static void Remove(string key)
            {
                Debug.Assert(!string.IsNullOrEmpty(key));

                if (HttpContext.Current.Items.Contains(key))
                {
                    HttpContext.Current.Items.Remove(key);
                }
            }
        }
    }
}
